# coding=utf-8

# 修复点赞数量.
import MySQLdb

Host = "118.31.32.197"
Port = 3306
User = "gmj"
Passwd = "123456"
Db = "worldcup"

conn = MySQLdb.connect(host=Host, port=Port, user=User, passwd=Passwd, db=Db, charset="utf8")
cursor = conn.cursor(cursorclass=MySQLdb.cursors.DictCursor)

sql = "select rec_openid, count(1) as num from userModel_travelevent where  event=1 group by rec_openid"
cursor.execute(sql)
rows = cursor.fetchall()
for row in rows:
	openid = row["rec_openid"]
	num = row["num"]
	# 判断与user表中是否相同
	cursor.execute("select support_num from userModel_user where openid='" + openid + "'")
	support_num = cursor.fetchall()[0]["support_num"]
	if support_num != num:
		print openid + " " + str(num) + ":" + str(support_num)
		# 更新
		cursor.execute("update userModel_user set support_num = " + str(num) + " where openid = '" + openid + "'")
cursor.execute("commit")
